<?php
   
session_start();
    include_once '../../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $oid = $_REQUEST['oid'];
    $usuario = $_SESSION['usuario'];
    
        $count ="select COUNT(*) as n from segimagenes where hcnsolexa = '".$oid."'";
        $res = $con->query($count);
    
    while($res2 = mssql_fetch_array($res)){
        $n = $res2['n'];
    }
    if ($n == 0){
        if ($usuario == ""){
            print_r(json_encode(array('n'=>1)));
        }else{
            $inser= "insert into segimagenes (hcnsolexa,segfecindi,segestado,usu_oid)values('".$oid."',GETDATE(),'1','".$_SESSION['usuario']."')";
            $con->query($inser);
            
            print_r(json_encode(array('n'=>2)));
        }
    }
    else {
        
        $update ="update segimagenes
                    set segestado ='1',
                    segfecindi = GETDATE(),
                    usu_oid ='".$_SESSION['usuario']."'
                  where hcnsolexa ='".$oid."'";
        $con->query($update);
   }
       
    $con->cerrarConexion();
    
 
?>